package com.dong.controller;

import com.dong.mybatis.entity.Zone1;
import com.dong.mybatis.mapper.Zone1Mapper;
import com.dong.utils.TimeRangeSampler;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("listdata")
@Slf4j
public class ListdataController {

    @Resource
    private Zone1Mapper zone1Mapper;

    @GetMapping("data")
    public List<Zone1> getListdata(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime) {

        log.info("接收到时间范围: {} -> {}", startTime, endTime);

        List<Zone1> sampled = TimeRangeSampler.sampleOnePerInterval(
                startTime,
                endTime,
                20,
                range -> zone1Mapper.selectByTimeRange(range.getStart(), range.getEnd())
        );

        log.info("查询结果大小：{} 😊😊", sampled.size());
        return sampled;
    }



}
